package com.jjc.android.fragment

import android.os.Bundle
import android.view.View
import android.widget.ImageView
import com.allen.library.SuperButton
import com.jjc.android.R
import com.jjc.android.activity.GuideActivity
import com.jjc.android.base.BaseFragment
import com.jjc.android.util.showImage
import com.jjc.android.view.onClick

class ScreenSlideFragment:BaseFragment() {

    companion object{
        fun newInstance(position:Int,url:String?,isEnd:Boolean):ScreenSlideFragment{
            val screenSlideFragment = ScreenSlideFragment()
            val bundle = Bundle()
            bundle.putInt("position", position)
            bundle.putString("url",url)
            bundle.putBoolean("isEnd",isEnd)
            screenSlideFragment.arguments = bundle
            return screenSlideFragment
        }
    }

    private lateinit var goIn: SuperButton
    private lateinit var imgview: ImageView

    private fun initViews(view: View) {
        imgview = view.findViewById(R.id.imgview)
        goIn = view.findViewById(R.id.goIn)
    }

    override fun getLayoutId(): Int = R.layout.fragment_guide

    override fun initView(view: View) {
        super.initView(view)
        initViews(view)

        val defaultImageRes = if (position == 0) {
            R.mipmap.guide_1
        } else if (position == 1) {
            R.mipmap.guide_2
        } else {
            R.mipmap.guide_3
        }
        imgview.showImage(imageUrl,defaultImageRes)

        if(isEndPosition){
            goIn.visibility = View.VISIBLE
            goIn.onClick {
                (activity as? GuideActivity)?.endTutorial()
            }
        }else{
            goIn.visibility = View.GONE
        }


    }

    private var position = 0
    private var imageUrl:String? = null
    private var isEndPosition = false
    override fun setupArguments(args: Bundle?) {
        position = args?.getInt("position")?:0
        imageUrl = args?.getString("url")
        isEndPosition = args?.getBoolean("isEnd")?:false
    }

}